package com.lesama.generics;

import java.util.ArrayList;
import java.util.List;

/*
    泛型通配符
        ?
        ? extends A: A或继承A的类型
        ? super A: A或是A父类的类型
 */

public class GenericsDemo5 {
    public static void main(String[] args) {
        List<Coder> list1 = new ArrayList<>();
        list1.add(new Coder());

        List<Manager> list2 = new ArrayList<>();
        list2.add(new Manager());

        method(list1);
        method(list2);
        List<Integer> list = new ArrayList<>();
        list.add(132);
        // method(list); // 报错，类型不匹配
    }
    public static void method(List<? extends Employee> list) {
        for (Employee o : list) {
            // Employee employee = (Employee) o; // 将o向下转型为Employee类型
            o.work();
        }
    }
}

abstract class Employee {
    abstract public void work();
}

class Manager extends Employee {

    @Override
    public void work() {
        System.out.println("经理管理");
    }
}

class Coder extends Employee {

    @Override
    public void work() {
        System.out.println("程序员敲代码");
    }
}